home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Format CD 22
/
Amiga Format AFCD22 (Jan 1998, Issue 106).iso
/
-seriously_amiga-
/
shareware
/
workbench
/
-dopus-
/
empdopus
/
source
/
unassign.rexx
< prev
next >
Wrap
OS/2 REXX Batch file
|
1997-11-05
|
11KB
|
347 lines
/*$VER: UnAssign.rexx 1.2 (18.10.97) B00ze
* For questions or comments email Booze@Videotron.CA
* Original idea (v1.0) by Charles Patterson <midian@azstarnet.com>
*
* Removes assigns pointing to the selected drawer(s) or the lister's path
* when no directory is selected. When called from anywhere but a lister
* toolbar, it will only work on the first SOURCE lister it finds;
* called from a lister toolbar works on that lister.
*
* Try this before brute-force Unlocking some directory...
*
* USAGE: AREXX: UnAssing.rexx {Qp} {Ql}
*
* PROGRAM HISTORY
*
* v1.1 -Knows about DEFER/PATH assigns; now, on request, only removes
* entries to the directory so that multipath volumes will still
* be there when you unassign parts of them; and no need to setup
* a list of volume names anymore!
*
* v1.2 -Improved signal traps.
* -Made a bunch of code into functions.
* -Requesters will be centered on the lister window whenever possible.
* -No longer deletes the tmp files on error, it was way too dangerous.
* -Indicates what it's using (Selected/Current Dir) in ListerTitle.
* -Simpler code to remove leading and trailing defer indicators <[()]>
* Unfortunately, you wont see any speed increase because of the new
* code to handle spaces and that damn Ram Disk :(
* -NOTE that you can't REMOVE a directory from a defered-type assign,
* the system just doesn't handle it - Assign.rexx will now show you
* if the assigns it finds are defered.
* -Now handles LOGICAL/ASSIGN names with spaces WITHIN, but NOT VOLUME
* names that contain spaces -with the exception of the Ram Disk- or
* assign names that begin/end with spaces! You should know better
* anyway. It does handle spaces in directory names though (this was
* always the case). I'd like to have it handle any volume name, but
* there's just no way to do it with the output Assign gives, I can't
* figure out when the assign name ends and when the volume name
* starts if they all have spaces in them...
*/
PN='UnAssign.rexx'
SH=0;WIN=0;LF='0A'x /* These are globals needed by almost every function I use! */
Options results
Signal ON SYNTAX
Signal ON BREAK_C
Signal ON FAILURE
Signal ON IOERR
Parse ARG P SH .
Address VALUE P
Options failat 21
/* MAIN */
If ~GSL() Then Call ReqERR('No Source Lister To Work With!') /* First, let's see if we got a lister to work with */
LP=GLP(SH) /* Get terminated lister path */
Call Pragma('D',LP) /* Get our directory name back using the volume name, non-terminated */
LP=Pragma('D')
/* Get the array of selected directories & rebuild it with the lister path */
DL.=0
'Lister Query' SH 'Seldirs Stem DL.'
If DL.count=0 Then Do /* Work on current directory instead of selected ones */
NL.0=LP
FL.=0
'Lister Query' SH 'Selentries Stem FL.'
If FL.count>0 Then Do x=0 To FL.count-1 /* Unselect files to indicate we work on the current dir */
'Lister Select' SH '"'FL.x'" 0'
End
'Lister Set' SH 'Title Looking for current dir...'
End
Else Do
If Right(LP,1)~=':'&Right(LP,1)~='/' Then LP=LP'/'
DL.count=DL.count-1
Do x=0 to DL.count
NL.x=LP||DL.x
End
'Lister Set' SH 'Title Looking for selected dirs...'
End
'Lister Refresh' SH 'FULL'
'Lister Set' SH 'Busy 1'
/* Get the list of assigned volumes and compare each node with our list */
FN='T:Unassign.'Pragma('ID')'.tmp' /* output file for assign list */
Address COMMAND 'C:Assign DIRS >'FN
If ~Open('F',FN,'R') Then Call ReqERR('Unable To Open C:Assign Outputfile!')
Do While ~EOF('F')
ALine=Strip(ReadLN('F'))
If ALine="Directories:" Then Leave /* Read past any crap */
End
Do While ~EOF('F')
ALine=Strip(ReadLN('F'))
If ALine~="" Then Do
Parse VAR ALine tmp ':' Dn
/* Twist alot and get the volume and the assign names */
tmp=Reverse(tmp)
If Upper(Left(tmp,8))="KSID MAR" Then Do /* Patch for that damn "Ram Disk" */
Dn='Ram Disk:'Dn
If Verify(Right(Dn,1),'>])','M') Then Do /* Add a char to the start of Dn so that the strip routine below works */
Dn='<'Dn
tmp=Substr(tmp,10)
End
Else tmp=Substr(tmp,9)
End
Else Dn=Reverse(Trim(Left(tmp,Pos(" ",tmp))))':'Dn
V.1=Trim(Reverse(Substr(tmp,(Pos(" ",tmp)+1))))
/* Trace Results;Say Dn;Say V.1;Trace Off */
If Verify(Right(Dn,1),'>])','M') Then Do /* Get rid of the Defered indicators */
Dn=Substr(Left(Dn,Length(Dn)-1),2)
Df=" DEFERED"
End
Else Df=""
/* Trace Results;Say Dn;Trace Off */
If V.1~="+" Then V.2=V.1 /* V2 keeps a copy of encountered volume names */
Do x=0 to DL.count
If NL.x=Dn Then Do
RC=ReqEZ('Found 'Upper(V.2)': -> 'NL.x||LF||Df||LF'Remove DIRECTORY or wipe entire ASSIGN?','Wipe _Assign|Remove _Directory|_Skip')
If RC=2 Then Address COMMAND 'C:Assign >NIL: "'V.2':" "'NL.x'" REMOVE'
Else If RC=1 Then Address COMMAND 'C:Assign >NIL: "'V.2':"'
If DL.count~=0 Then Do
'Lister Select' SH '"'DL.x'" 0'
'Lister Refresh' SH
End
End
End
End
End
'Lister Set' SH 'Title'
'Lister Set' SH 'Busy 0'
'Lister Refresh' SH 'FULL'
Call Close('F')
'Command Delete' '"'FN'"' 'QUIET'
Exit 0
/*-----------------------------------------------------------
Get Source Lister
You MUST Initialise WIN and SH to Zer0!
-----------------------------------------------------------*/
/* Returns the GLOBALS SH and WIN, the idea being that all requesters
* should appear within the calling window. When SH is already set to
* a non-zero numeric value, we assume we've parsed a valid {Ql} arg.
*
* When SH is zero, we query Dopus for a SOURCE-Lister. If we are
* passed 'D' we try for a DEST-Lister when no SOURCE-Lister can be
* obtained. If we are passed 'A' we try for that when DEST fails. */
GSL: PROCEDURE EXPOSE P LF PN SH WIN /* USAGE: Success=GSL(Scantype) */
If Datatype(SH)~="NUM" Then Call ReqERR('UnInitialized SH/SourceHandle!')
If SH=0 Then Do
Parse UPPER ARG STyp
If STyp~="D"|STyp~="A" Then STyp="S"
SL.=0
'Lister Query Source Stem SL.'
If SL.count=0 Then If STyp="S" Then Return(0)
Else Do
'Lister Query Dest Stem SL.'
If SL.count=0 Then If STyp="D" Then Return(0)
Else Do
'Lister Query ALL Stem SL.'
If SL.count=0 Then Return(0)
End
End
SH=SL.0
End
'Lister Set' SH 'Source'
'Lister Query' SH 'Window'
If RESULT~=0&Datatype(RESULT)='NUM' Then WIN=RESULT
Else WIN=0
Return(1)
/*-----------------------------------------------------------
Get Terminated Lister Path
-----------------------------------------------------------*/
GLP: PROCEDURE EXPOSE P LF PN SH WIN /* USAGE: Path=GLP(ListerHandle) */
Parse ARG LH
'Lister Query' LH 'PATH'
If RESULT=""|RESULT="RESULT" Then Call ReqERR('Unable To Obtain Lister PATH!')
Else Do
LP=RESULT
If Right(LP,1)~=':'&Right(LP,1)~='/' Then LP=LP'/'
End
Return(LP)
/*-----------------------------------------------------------
Requesters
All functions assume the current port to be Dopus's
-----------------------------------------------------------*/
/* All requesters work on the calling lister, specified by the globals
* SH/WIN, when set. To force a lister to appear centered on the dopus
* screen instead, supply the extra switch 'NW' for 'NoWin-Centered' */
ReqEZ: PROCEDURE EXPOSE P LF PN FN SH WIN /* USAGE: GReqEZ('requestertext','gadgets'[,'NW']) */
Parse ARG TXT,GADGETS,A
A=Upper(A)
If ~Show('L',"rexxreqtools.library") Then CALL AddLib('rexxreqtools.library',0,-30,0) /* Try to get rexxreqtools loaded */
If ~Show('L',"rexxreqtools.library") Then Do
GADGETS=Compress(GADGETS,'_')
If SH=0|Datatype(SH)~="NUM"|A="NW" Then RCMD='Dopus Request'
Else RCMD='Lister Request 'SH
RCMD' "'TXT'" 'GADGETS
Choice=RC
End
Else Do
If WIN=0|Datatype(WIN)~="NUM"|A="NW" Then Do
'Dopus Screen'
Parse VAR RESULT S .
RTAG='RT_PubScrName='S' rt_reqpos=reqpos_centerscr'
End
Else RTAG='RT_Window='WIN' rt_reqpos=reqpos_centerwin'
Choice=rtEZRequest(TXT,GADGETS,PN,RTAG' rtez_flags=ezreqf_centertext')
End
Return Choice
ReqERR: PROCEDURE EXPOSE P LF PN FN SH WIN /* USAGE: GReqERR('requestertext'[,'NW']) - Quits! */
Parse ARG TXT,A
A=Upper(A)
'Command Flash'
If ~Show('L',"rexxreqtools.library") Then CALL AddLib('rexxreqtools.library',0,-30,0) /* Try to get rexxreqtools loaded */
If ~Show('L',"rexxreqtools.library") Then Do
If SH=0|Datatype(SH)~="NUM"|A="NW" Then RCMD='Dopus Request'
Else RCMD='Lister Request 'SH
RCMD' "+++ 'PN' Error +++'LF||TXT'" OK'
End
Else Do
If WIN=0|Datatype(WIN)~="NUM"|A="NW" Then Do
'Dopus Screen'
Parse VAR RESULT S .
RTAG='RT_PubScrName='S' rt_reqpos=reqpos_centerscr'
End
Else RTAG='RT_Window='WIN' rt_reqpos=reqpos_centerwin'
CALL rtEZRequest('+++ 'PN' Error +++'LF||TXT,,PN,RTAG' rtez_flags=ezreqf_centertext rt_idcmpflags=idcmp_vanillakey')
End
If SH~=0 Then Do
'Lister Set' SH 'Busy 0'
'Lister Set' SH 'Title'
'Lister Refresh' SH 'FULL'
End
Exit 20
/*-----------------------------------------------------------
ERROR HANDLERS
-----------------------------------------------------------*/
BREAK_C:
Address VALUE P
If SH~=0 Then Do
'Lister Set' SH 'Busy 0'
'Lister Set' SH 'Title'
'Lister Refresh' SH 'FULL'
RCMD='Lister Request 'SH
End
Else RCMD='Dopus Request'
'Command Flash'
RCMD' "+++ Break! +++" OK'
Call Close('F')
Exit 0
SYNTAX:
RCX=RC
Address VALUE P
If SH~=0 Then Do
'Lister Set' SH 'Busy 0'
'Lister Set' SH 'Title'
'Lister Refresh' SH 'FULL'
RCMD='Lister Request 'SH
End
Else RCMD='Dopus Request'
'Command Flash'
RCMD' "+++ Syntax Error +++'LF'('RCX') at line 'SIGL||LF||errortext(RCX)'" OK'
Call Close('F')
Exit 20
FAILURE:
Address VALUE P
If SH~=0 Then Do
'Lister Set' SH 'Busy 0'
'Lister Set' SH 'Title'
'Lister Refresh' SH 'FULL'
RCMD='Lister Request 'SH
End
Else RCMD='Dopus Request'
'Command Flash'
RCMD' "+++ Failure +++'LF'Something failed at line 'SIGL'" OK'
Call Close('F')
Exit 20
IOERR:
Address VALUE P
If SH~=0 Then Do
'Lister Set' SH 'Busy 0'
'Lister Set' SH 'Title'
'Lister Refresh' SH 'FULL'
RCMD='Lister Request 'SH
End
Else RCMD='Dopus Request'
'Command Flash'
RCMD' "+++ I/O Error +++'LF'I/O Operation failed at line 'SIGL'" OK'
Call Close('F')
Exit 20